The code that implements the Sparkplug host application or edge node (using Rapid Toolkit for Sparkplug) cannot just be written and built - it ultimately needs to be run, and for it it needs to be hosted in some kind of executable application. There are many hosting options; the Rapid Toolkit for Sparkplug does no artificially limit them, but some are more common and practical than others. This article will specifically address certain typical hosting scenarios. However, other hosting options exist as well.
When developing a Sparkplug host application, your code needs to create an instance of the EasySparkplugConsumer Class, set its properties and then call some of the methods for data subscription or publication.
When developing a Sparkplig edge node, your code needs to create an instance of the EasySparkplugEdgeNode Class, se its properties and populate it with metrics (and optionally devices and their metrics). It then needs to call the Start Method on the edge node object. When this happens depends on the hosting scenario. The edge node is started, and it keeps running. At some later moment, when the edge node needs to be shut down, your code should call the Stop Method. The host may require additional code in order to integrate it with your edge node.
Hosting the Sparkplug host application or edge node in a console application is probably the easiest option in terms of coding effort needed to implement it; and the same time, it is also very easy to debug. There is almost no extra code necessary to make the host application or edge node work inside the console application.
Example - Sparkplug host application in a console host
The following examples illustrates a fully functional Sparkplug host application based on Rapid Toolkit for Sparkplug, hosted in a console application. The host application subscribes to all edge node metrics and all metrics on all devices of the given Sparkplug edge node, and displays the incoming data. Status information related to the broker connection comes via the same events and is also displayed.
Examples - Sparkplug edge node in a console host
The following example illustrates a fully functional Sparkplug edge node based on Rapid Toolkit for Sparkplug, hosted in a console application. The edge node also outputs information such as the state of its connection to the broker, errors in publishing, and the birth/rebirth and death events.
Sparkplug host applications and edge nodes developed with Rapid Toolkit for Sparkplug can be hosted inside a Windows desktop application developed using Windows Forms (and in fact, the application can also be developed using WPF or other tools). This hosting option provides a possibility of integrating the Sparkplug host application or edge node with rich user interface, inside the same process.
Hosting your Sparkplug host application or edge node in a Windows service is meant mainly for "head-less", fully automated operations. The Windows service has several advantages over other hosting options. The service can be started and stopped in various ways provided by the operating system, and it can even start together with the operating system. The service can operate without any interactive user being logged in, and it can be configured to run under a specific user account. See e.g. the ServiceBase Class documentation for more information on developing Windows Services in this way.
The "worker service" (Worker services in .NET) is a basically a modern way of creating a service-like application in .NET - not just Windows service, but eventually also a Linux daemon, etc. Rapid Toolkit for Sparkplug host applications and edge nodes can be hosted in the .NET worker service as well.
Sparkplug is a trademark of Eclipse Foundation, Inc. "MQTT" is a trademark of the OASIS Open standards consortium. Other related terms are trademarks of their respective owners. Any use of these terms on this site is for descriptive purposes only and does not imply any sponsorship, endorsement or affiliation.